package com.open.system.controller;

import com.open.common.utils.PageUtils;
import com.open.common.utils.Query;
import com.open.common.utils.R;
import com.open.system.domain.LoanJuxinliPostInfoDO;
import com.open.system.service.LoanJuxinliPostInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author aaa
 * @email aaax
 * @date 2018-11-02 22:25:29
 */

@Controller
@RequestMapping("/system/loanJuxinliPostInfo")
public class LoanJuxinliPostInfoController {
    @Autowired
    private LoanJuxinliPostInfoService loanJuxinliPostInfoService;

    @GetMapping()
    @RequiresPermissions("system:loanJuxinliPostInfo:loanJuxinliPostInfo")
    String LoanJuxinliPostInfo() {
        return "system/loanJuxinliPostInfo/loanJuxinliPostInfo";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("system:loanJuxinliPostInfo:loanJuxinliPostInfo")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<LoanJuxinliPostInfoDO> loanJuxinliPostInfoList = loanJuxinliPostInfoService.list(query);
        int total = loanJuxinliPostInfoService.count(query);
        PageUtils pageUtils = new PageUtils(loanJuxinliPostInfoList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("system:loanJuxinliPostInfo:add")
    String add() {
        return "system/loanJuxinliPostInfo/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("system:loanJuxinliPostInfo:edit")
    String edit(@PathVariable("id") Long id, Model model) {
        LoanJuxinliPostInfoDO loanJuxinliPostInfo = loanJuxinliPostInfoService.get(id);
        model.addAttribute("loanJuxinliPostInfo", loanJuxinliPostInfo);
        return "system/loanJuxinliPostInfo/edit";
    }

    @GetMapping("/getJsonInfoById/{id}")
    @RequiresPermissions("system:loanJuxinliPostInfo:loanJuxinliPostInfo")
    String getJsonInfoById(@PathVariable("id") Long id, Model model) {
        LoanJuxinliPostInfoDO loanJuxinliPostInfo = loanJuxinliPostInfoService.get(id);
        model.addAttribute("loanJuxinliPostInfo", loanJuxinliPostInfo);
        return "system/loanJuxinliPostInfo/juxinliPostJsonInfo";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("system:loanJuxinliPostInfo:add")
    public R save(LoanJuxinliPostInfoDO loanJuxinliPostInfo) {
        if (loanJuxinliPostInfoService.save(loanJuxinliPostInfo) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("system:loanJuxinliPostInfo:edit")
    public R update(LoanJuxinliPostInfoDO loanJuxinliPostInfo) {
        loanJuxinliPostInfoService.update(loanJuxinliPostInfo);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("system:loanJuxinliPostInfo:remove")
    public R remove(Long id) {
        if (loanJuxinliPostInfoService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("system:loanJuxinliPostInfo:batchRemove")
    public R remove(@RequestParam("ids[]") Long[] ids) {
        loanJuxinliPostInfoService.batchRemove(ids);
        return R.ok();
    }

}
